# -*- coding:utf-8 -*-
from Tkinter import *
import tkFont

class DpWin(object):
    def run(self):
        self.root=Tk()
        self.root.geometry('768x612')
        title='dp'
        self.root.title(title)
        #字体
        font = tkFont.Font(family = 'Verdana',size = 13)
        self.f1 = Frame(self.root)              #
        
        self.f11 = Frame(self.f1)               #url
        label2 = Label(self.f11, font=font,text='url: ')
        label2.pack(side = LEFT)
        self.entry_url=Entry(self.f11,width=30,font=font)
        self.entry_url.pack(fill = X,expand = 1,side = RIGHT)
        
        self.f12 = Frame(self.f1)               #标签
        label3 = Label(self.f12, font=font,text=' 标签: ')
        label3.pack(side = LEFT)
        self.entry_tag=Entry(self.f12,width=10,font=font)
        self.entry_tag.pack(fill = X,expand = 1,side = RIGHT,padx=2)
        
        self.f2 = Frame(self.root)              #
        
        self.f21 = Frame(self.f2)               #列表
        self.f211 = Frame(self.f21)
        self.f212 = Frame(self.f21)

        scrollbarx = Scrollbar(self.f211, orient=HORIZONTAL)
        scrollbarx.pack(side=BOTTOM,fill=X)
        scrollbary = Scrollbar(self.f211, orient=VERTICAL)
        scrollbary.pack(side=RIGHT, fill=Y)
        
        self.textarea=Text(self.f211,height=40,wrap=NONE,xscrollcommand=scrollbarx.set,yscrollcommand=scrollbary.set)
        self.textarea.config(state=DISABLED)
        scrollbarx.config(command=self.textarea.xview)
        scrollbary.config(command=self.textarea.yview)
        self.textarea.pack(fill=BOTH, expand=1)
        
        #scrollbary = Scrollbar(self.f211, orient=VERTICAL)
        #scrollbarx = Scrollbar(self.f211, orient=HORIZONTAL)
        #self.listbox = Listbox(self.f211,height=35,yscrollcommand=scrollbary.set,xscrollcommand=scrollbarx.set,selectmode=EXTENDED)
        #scrollbary.config(command=self.listbox.yview)
        #scrollbary.pack(side=RIGHT, fill=Y)
        
        #self.listbox.pack(fill=BOTH, expand=1)
        #scrollbarx.config(command=self.listbox.xview)
        #scrollbarx.pack(fill=X)
        #listbox计数
        #label_count_tag = Label(self.f212,text='count: ')
        #label_count_tag.pack(side = LEFT,pady=2)
        #self.label_count = Label(self.f212, font=font,text='0')
        #self.label_count.pack(side = LEFT,pady=2)

        self.f211.pack(fill = BOTH,expand = 1)
        self.f212.pack(fill = X,expand = 1)
        
        self.f22 = Frame(self.f2)               #按钮
        self.b_start=Button(self.f22,text='启动',command=self.start)
        self.b_start.config(height=3,width=10)
        self.b_start.pack()
        self.b_stop=Button(self.f22,text='停止',state=DISABLED,command=self.stop)
        self.b_stop.config(height=3,width=10)
        self.b_stop.pack()

        self.f11.pack(fill = X,expand = 1,side = LEFT)
        self.f12.pack(fill = X,expand = 1,side = RIGHT)
        self.f21.pack(fill = BOTH,expand = 1,side = LEFT,padx=5)
        self.f22.pack(side = RIGHT,padx=2)

        self.f1.pack(fill = X,pady=6)
        self.f2.pack(fill = BOTH,expand = 1,pady=16)
        
        mainloop()
    #启动按钮响应函数
    def start(self):
        self.b_start.config(state=DISABLED)
        self.b_stop.config(state=ACTIVE)
        self.insert_textarea('start\n')
    #停止按钮响应函数
    def stop(self):
        self.b_stop.config(state=DISABLED)
        self.b_start.config(state=ACTIVE)
        self.insert_textarea('stop\n')
    #url
    def get_entry_url(self):
        content=self.entry_url.get()
        return content
    def set_entry_url(self,content):
        self.entry_url.delete(0,END)
        self.entry_url.insert(0,content)
    #标签
    def get_entry_tag(self):
        content=self.entry_tag.get()
        return content
    def set_entry_tag(self,content):
        self.entry_tag.delete(0,END)
        self.entry_tag.insert(0,content)
    #文本域
    def get_textarea(self):
        content=self.textarea.get(0,END)
        return content
    def insert_textarea(self,content,position=None):
        self.textarea.config(state=NORMAL)
        if position==None:
            self.textarea.insert(END,content)
        else:
            self.textarea.insert(position,content)
        #self.textarea.see(0.0)
        self.textarea.see(END)
        self.textarea.config(state=DISABLED)
        
    #列表
    def listbox_insert(self,item,position=0):
        if position==0:
            self.listbox.insert(END, item)
        else:
            self.listbox.insert(position,item)
        self.calculate_listbox_count()
    #统计列表数目
    def calculate_listbox_count(self):
        size=self.listbox.size()
        self.label_count.config(text=size)
if __name__=='__main__':
    win=DpWin()
    win.run()








